package com.xinqi.modules.sys.gpt.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.modules.sys.gpt.dto.req.ShareQuotaCreateDTO;
import com.xinqi.modules.sys.gpt.dto.req.ShareQuotaQueryDTO;
import com.xinqi.modules.sys.gpt.dto.req.ShareQuotaUpdateDTO;
import com.xinqi.modules.sys.gpt.dto.rsp.ShareQuotaResultDTO;
import com.xinqi.modules.sys.gpt.service.ShareQuotaService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * ADMIN -- 邀请规则
 *
 * @author: yyzhen
 * @date: 2023/05/23
 */
@Validated
@RestController
@RequestMapping("/admin/share-quota")
@RequiredArgsConstructor
public class ShareQuotaAdminController {
    private final ShareQuotaService shareQuotaService;

    @Operation(summary = "邀请规则表-分页")
    @GetMapping("/page")
    public R<PageInfo<ShareQuotaResultDTO>> page(@ParameterObject ShareQuotaQueryDTO dto) {
        PageInfo<ShareQuotaResultDTO> page = shareQuotaService.page(dto, dto);
        return R.data(page);
    }

    @Operation(summary = "邀请规则表-详情")
    @GetMapping("/info/{id}")
    public R<ShareQuotaResultDTO> findById(@NotNull(message = "{gpt.share.quota.id.not.blank}") @PathVariable("id") Long id) {
        ShareQuotaResultDTO dto = shareQuotaService.findById(id);
        return R.data(dto);
    }


    @Operation(summary = "新增邀请规则")
    @PostMapping("/add")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 新增邀请规则", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Long> insert(@Validated @RequestBody ShareQuotaCreateDTO dto) {
        return R.data(shareQuotaService.insert(dto));
    }

    @Operation(summary = "修改邀请规则")
    @PostMapping("/edit")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 修改邀请规则", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> update(@Validated @RequestBody ShareQuotaUpdateDTO dto) {
        return R.data(shareQuotaService.updateById(dto));
    }

    @Operation(summary = "删除邀请规则")
    @GetMapping("/remove/{id}")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 删除邀请规则", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> delete(@NotNull(message = "{gpt.share.quota.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(shareQuotaService.deleteById(id));
    }
}
